package com.itxh.mybatis.test;


import com.itxh.core.builder.SqlSessionFactoryBuilder;
import com.itxh.core.factory.SqlSessionFactory;
import com.itxh.core.io.Resources;
import com.itxh.mybatis.dao.UserDao;
import com.itxh.mybatis.dao.UserDaoImplWithMybatis;
import com.itxh.mybatis.po.User;
import org.junit.Before;
import org.junit.Test;

import java.io.InputStream;
import java.util.List;

public class UserDaoTestWithMybatis {
	private SqlSessionFactory sqlSessionFactory;

	@Before
	public void before(){
		InputStream inputStream = Resources.getResourceAsStream("SqlMapConfig.xml");
		sqlSessionFactory = new SqlSessionFactoryBuilder().build(inputStream);
	}

	@Test
	public void testQueryUserById() {
		UserDao userDao = new UserDaoImplWithMybatis(sqlSessionFactory);
		User user = userDao.queryUserById(2);
		System.out.println(user);

	}

	@Test
	public void testQueryUserByName() {
		UserDao userDao = new UserDaoImplWithMybatis(sqlSessionFactory);

		List<User> users = userDao.queryUserByName("小妲己");
		System.out.println(users);

	}
}
